package com.oriental.manage.controller.reserve.config;

import com.oriental.manage.core.paging.Pagination;
import com.oriental.manage.core.response.ResponseDTO;
import com.oriental.manage.core.utils.SessionUtils;
import com.oriental.manage.service.reserve.ReportReviewConfigService;
import com.oriental.reserve.model.config.ReportReviewCfgDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author: Yang xp
 * Date: 2017/5/19
 * Time: 9:13
 * Desc：报表填报人和审核人配置
 */
@RequestMapping("/reserve/review/cfg")
@Controller
@Slf4j
public class ReportReviewConfigController {

    @Autowired
    private ReportReviewConfigService reportReviewConfigService;

    @RequestMapping("/init")
    public String init(){
        return "reserve/config/searchReportReviewConfig";
    }

    @RequestMapping("/toUpdate")
    public String toUpdate(){
        return "reserve/config/updateReportReviewConfig";
    }

    @RequestMapping("/update")
    @ResponseBody
    public ResponseDTO<String> update(@RequestBody ReportReviewCfgDto reportReviewCfgDto){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        log.info("修改信息:{}",reportReviewCfgDto);
        try {
            reportReviewCfgDto.setUpdateBy(SessionUtils.getUserName());
            reportReviewConfigService.update(reportReviewCfgDto,responseDTO);
        } catch (Exception e) {
            log.error("修改失败", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("修改失败");
        }
        return responseDTO;
    }

    @RequestMapping("/search")
    @ResponseBody
    public ResponseDTO<Pagination<ReportReviewCfgDto>> search(ReportReviewCfgDto reportReviewCfgDto){
        ResponseDTO<Pagination<ReportReviewCfgDto>> responseDTO = new ResponseDTO<>();
        try{
            Pagination<ReportReviewCfgDto> pagination = new Pagination<>();
            log.info("查询信息:{},{}",reportReviewCfgDto);
            reportReviewConfigService.search(pagination,reportReviewCfgDto,responseDTO);
            responseDTO.setSuccess(true);
            responseDTO.setObject(pagination);
        }catch(Exception e){
            log.error("查询失败", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("查询失败");
        }
        return responseDTO;
    }


}
